package com.itheima.controller;

import com.itheima.common.PaginationVO;
import com.itheima.common.Result;
import com.itheima.service.FriendshipLinkService;
import com.itheima.vo.LinkVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ydd_link")
@Slf4j
@RequiredArgsConstructor
public class FriendshipLinkController {
    private final FriendshipLinkService friendshipLinkService;

    @GetMapping("/list")
    public Result<PaginationVO<LinkVO>> page(String type,
                  @RequestParam(defaultValue = "1") String page,
                  @RequestParam(defaultValue = "10") String limit) {
        //记录日志
        log.info("分页查询，参数：{},{},{}", page, limit,type);
        //调用业务层分页查询功能
        PaginationVO<LinkVO> pages = friendshipLinkService.page(page, limit, type);
        //响应
        return Result.success(pages);
    }
    @PostMapping("/add")
    public Result<?> addLink(@RequestBody LinkVO linkVO) {
        friendshipLinkService.addLink(linkVO);
        return Result.success();
    }
    @PostMapping("/update")
    public Result<?> updateLink(@RequestBody LinkVO linkVO) {
        friendshipLinkService.updateLink(linkVO);
        return Result.success();
    }

    @GetMapping("/rowInfo")
    public Result<LinkVO> rowInfoLink(Integer id) {
        LinkVO link = friendshipLinkService.rowInfoLink(id);
        return Result.success(link);
    }

    @GetMapping("/del")
    public Result<?> deleteAdvimg(Integer id) {
        friendshipLinkService.deleteLink(id);
        return Result.success();
    }
}
